package com.ttsx.controller;

import com.ttsx.core.common.result.Result;
import com.ttsx.pojo.dto.order.OrderCreateDTO;
import com.ttsx.pojo.dto.order.OrderQueryDTO;
import com.ttsx.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author wb
 * @since 2025-03-02
 */

@RestController
@RequestMapping("order")
public class OrderController {

    @Autowired
    private OrderService orderService;


    @PostMapping("create")
    public Result<?> createOrder(@RequestBody OrderCreateDTO orderCreateDTO) {
        return Result.success(orderService.createOrder(orderCreateDTO));
    }


    @PostMapping("page/{pIndex}/{pSize}")
    public Result<?> pageOrder(
            @PathVariable("pIndex") Integer pIndex,
            @PathVariable("pSize") Integer pSize,
            @RequestBody OrderQueryDTO orderQueryDTO) {
        return Result.success(orderService.getPage(pIndex, pSize, orderQueryDTO));
    }

    @GetMapping("shipped/{orderNo}")
    public Result<?> shipped(@PathVariable String orderNo) {
        return orderService.shipped(orderNo) ? Result.success() : Result.failure();
    }
}
